import {reqshop} from "@/common/api";

const initialState = {
  shopdata: {}
};

export const types = {
  CHANGE_SHOPDATA: 'shop/CHANGE_SHOPDATA'
}

// action creators
export const actions = {
  changeShopData: data => ({
    type: types.CHANGE_SHOPDATA,
    data: data
  })
}

export const getShopData = () => {
  return (dispatch) => {
    reqshop().then((res) => {
      console.log(res)
      console.log('res -----------')
      dispatch(actions.changeShopData(res.data))
    }).catch(() => {
      console.log('出错了');
    })
  }
}

const reducer = (state = initialState, action) => {
  switch (action.type) {
    case types.CHANGE_SHOPDATA:
      return {...state, shopdata: action.data}
    default:
      return state;
  }
}

export default reducer;
